<template>
	<om-page title="扫码">
		<view class="padding-xl text-center text-xxl bg-steelblue">欢迎使用OM系统</view>
		<view class="content">
			<om-wing-blank>
				<view class="input-group">
					<view class="input-row">
						<text class="title">网址：</text>
						<m-input type="text" clearable v-model="stateurl" placeholder="请输入网址"></m-input>
						<image class="wechat" mode="aspectFit" src="/static/images/others/wechat.png" @tap="scan"></image>
					</view>
				</view>
				<!-- <view class="check-box"><i class="check" :class="check == true ? 'selected' : ''" @tap="selectCheck"></i><a @tap="showPrivacy" class="checkdes">隐私政策</a>和<a @tap="showAgree" class="checkdes">用户协议</a></view> -->
				<view class="btn-row" style="margin-top: 0;"><button type="primary" class="primary" @tap="bindLogin">确认</button></view>
				<view style="text-align:center">温馨提示：不清楚网址请联系系统管理员</view>
			</om-wing-blank>
		</view>
		<!-- #ifdef APP || APP-PLUS || APP-NVUE || APP-PLUS-NVUE || APP-VUE -->
		<ot-authpup ref="authpup" type="top" @changeAuth="changeAuth" permissionID="CAMERA"></ot-authpup>
		<!-- #endif -->
	</om-page>
</template>

<script>
import md5 from '@/static/js/md5.js';
import service from '@/service.js';
import orgMap from '@/static/json/orgList.json'
export default {
	data() {
		return {
			stateurl: '',
			wechatimg: '/static/images/others/wechat.png',
			// check: false,
		};
	},
	onLoad(e) {
		let _that = this;
		uni.getStorage({
			key: "ORG_SITE",
			success(res) {
				if (res.data) {
					_that.stateurl = res.data.site
					// _that.check = true
				}
			}
		})
	},
	methods: {
		scan(){
			let _that = this;
			
			uni.showModal({
				title: '对相机权限申请说明',
				content: '便于您使用该功能拍照、扫码等功能,是否使用？',
				cancelText: "否", 
				confirmText: "是",
				showCancel: true,
				success: (res) => {
					if(res.confirm) { 
						uni.scanCode({
						    onlyFromCamera: true,
						    success: function (res) {
								_that.stateurl = res.result
						    },
							fail: function(msg){
								_that.om.toast(msg);
							}
						});
					}
				}
			})
			// // #ifdef APP || APP-PLUS || APP-NVUE || APP-PLUS-NVUE || APP-VUE
			// setTimeout(()=>{
			// 	this.$refs['authpup'].open();
			// },500)
			// // #endif
		},
		bindLogin(){
			let _that = this;
			if (!_that.stateurl) {
				// _that.om.toast('网址不能为空！');
				uni.removeStorageSync('ORG_SITE')
				uni.redirectTo({
					url: '/pages/login/login/login'
				});
				return;
			}
			// if(_that.check != true){
			// 	_that.om.toast('请阅读并勾选“隐私政策和用户协议”');
			// 	return;
			// }
			
			if(!_that.stateurl.endsWith("/")){
				_that.stateurl = _that.stateurl + "/"
			}
			uni.request({
				url: _that.stateurl+'version/check.do',
				data:{
					loginType: service.getAppType()
				},
				success: (res) => {
					if(res.data.succeed){
						if(res.data.value) {
							if(res.data.value == "SUCCESS"){
								uni.setStorage({
									key: 'ORG_SITE',
									data: {site: _that.stateurl}
								});
							} else {
								uni.setStorage({
									key: 'ORG_SITE',
									data: {site: _that.stateurl, name:res.data.value}
								});
							}
							uni.redirectTo({
								url: '/pages/login/login/login'
							});
						}
					}else{
						_that.om.toast('请输入正确的网址！');
					}
				},
				fail: (msg) => {
					_that.om.toast('请输入正确的网址！');
				}
			})
			
		},
		// showPrivacy(){
		// 	uni.navigateTo({
		// 	    url: '/pages/login/privacypolicy/privacy-policy'
		// 	});
		// },
		// showAgree(){
		// 	uni.navigateTo({
		// 	    url: '/pages/login/privacypolicy/user-agreement'
		// 	});
		// },
		// selectCheck(){
		// 	this.check = !this.check
		// },
		changeAuth(){
			
		}
	}
};
</script>
<style scoped>
	.check-box{
		margin-top: 10px;
		position: relative;
		overflow: hidden;
	}
	.check{
		float: left;
		margin: 2px 5px 0 10px;
		width: 16px;
		height: 16px;
		display: block;
		background: url("") no-repeat;
	}
	.check.selected{
		background: url("") no-repeat;
	}
	.checkdes{
		color: #0faeff;
		line-height: 20px;
	}
</style>
